<?php
App::uses('AppController', 'Controller');
/**
 * Paralelos Controller
 *
 * @property Paralelo $Paralelo
 */
class AulasController extends AppController {

    public $uses = array('Aula');
    public $layout = 'colegio';
    public function beforeFilter()
    {
        parent::beforeFilter();
        //$this->Auth->allow('*');
    }
    
    public function index(){
        $aulas = $this->Aula->find('all', array(
            'recursive'=>0           
            ));
        $this->set(compact('aulas'));
    }
        function insertar(){
        if(!empty($this->data)){
            if($this->Aula->save($this->data)){
                $this->Session->setFlash('Se Guardo Correctamente!!!');
                $this->redirect(array('action'=>'index')); 
              
            }
            else{
                $this->Session->setFlash('Error al Guardar consulte con el Administrador de Sistema');
            }
        }
    }

    function editar($id=null){
        $this->Aula->id=$id;
        if(!$id){
            $this->Session->setFlash('No Existe el tipo de Aula');
            $this->redirect(array('action' =>'index'));
        }
        if(empty($this->data)){
            $this->data=$this->Aula->read();
        }
        else{
            if($this->Aula->save($this->data)){
                $this->Session->setFlash('Se Guardo Correctamente el Aula');
                $this->redirect(array('action'=>'index'));
                }
                else{
                    $this->Session->setFlash('Error al guardar el Aula');
                }
        }
    }
    
    function eliminar($id=null){
        $this->Aula->id=$id;
        $this->data=$this->Aula->read();
        if(!$id){
            $this->Session->setFlash('No existe el Aula a Eliminar');
            $this->redirect(array('action' =>'index'));
        }
        else{
            if($this->Aula->delete($id)){
                $this->Session->setFlash('Se elimino el Aula '.$this->data['Aula']['nombre']);
                $this->redirect(array('action' =>'index'));
            }
            else{
                $this->Session->setFlash('Error al eliminar');
            }
        }
    }
}
